package com.web.hilover.controller;

import com.web.hilover.entity.User;
import com.web.hilover.service.LikeService;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping("/comments")
@Slf4j
public class CommentController {

    @Autowired
    private LikeService likeService;
    
    @PostMapping("/{id}/like")
    @ResponseBody
    public Map<String, Object> likeComment(@PathVariable Long id, HttpSession session) {
        User user = (User) session.getAttribute("loginUser");
        if (user == null) {
            return Map.of("success", false, "message", "请先登录");
        }
        
        try {
            likeService.likeComment(id, user.getId());
            return Map.of("success", true);
        } catch (Exception e) {
            return Map.of("success", false, "message", e.getMessage());
        }
    }
} 